package com.yao.item.rabbitmq;



import com.alibaba.druid.sql.visitor.functions.Bin;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Map;

/**
 * 配置bean
 */
@Configuration
public class MqConfig {
    public static final String SECKILL_QUEUE = "seckill.queue";
    public static final String QUEUE = "queue";
    public static final String TOPIC_QUEUE1 = "topic.queue1";
    public static final String TOPIC_QUEUE2 = "topic.queue2";
    public static final String TOPIC_EXCHANGE = "topicExchage"; //交换机

//
//            1、name: 队列的名称；
//            2、actualName: 队列的真实名称，默认用name参数，如果name为空，则根据规则生成一个；
//            3、durable: 是否持久化；
//            4、exclusive: 是否独享、排外的；
//            5、autoDelete: 是否自动删除；
//public Queue(String name, boolean durable, boolean exclusive, boolean autoDelete, Map<String, Object> arguments)

    /**
     * Direct模式 交换机Exchange
     * 发送者先发送到交换机上，然后交换机作为路由再将信息发到队列，
     * */
    @Bean
    public Queue getque(){
        return  new Queue(QUEUE,true);
    }

    /**
     * Topic模式 交换机Exchange
     * */
    @Bean
    public Queue topicQueue1() {
        return new Queue(TOPIC_QUEUE1, true);
    }
    @Bean
    public Queue topicQueue2() {
        return new Queue(TOPIC_QUEUE2, true);
    }
    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange(TOPIC_EXCHANGE);
    }

//    绑定
    @Bean
    public Binding topicBinding1(){
        return BindingBuilder.bind(topicQueue1()).to(topicExchange()).with("topic.key1");

    }
//    # 匹配一个或多个词
    public Binding topicBinding2(){
        return BindingBuilder.bind(topicQueue2()).to(topicExchange()).with("topic.#");
    }


}
